package me.huangxiang.data_structure_and_algorithm.sort;

public class InsertionSort {
    public static void insertionSort(int[] a){
        int length = a.length;
        for (int i = 1; i < length; i++){

            int preIndex = i - 1;
            int current = a[i];

            while (preIndex >= 0 && a[preIndex] > current){
                a[preIndex + 1] = a[preIndex];
                preIndex--;
            }
            a[preIndex + 1] = current;
        }
    }
}
